package com.acxiom.foodreview.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.acxiom.foodreview.dao.ExamplesMapper;
import com.acxiom.foodreview.entity.Examples;
import com.acxiom.foodreview.entity.Page;
import com.acxiom.foodreview.service.ExamplesService;

/**
 * Created by hadong on 2017-03-23. exampleServiceImpl
 */
@Service
public class ExamplesServiceImpl implements ExamplesService {

	private static final Logger logger = Logger.getLogger(ExamplesServiceImpl.class);

	@Autowired
	private ExamplesMapper mapper;

	@Override
	public boolean insert(Examples examples) {
		logger.info("<-- service add start -->");
		return mapper.insert(examples) > 0;
	}

	@Override
	public Examples findById(Integer id) {
		return mapper.findById(id);
	}

	@Override
	public Page<Examples> findAsPage(int page, int rows) {
		Page<Examples> pages = new Page<Examples>();
		int offset = (page - 1) * rows;
		List<Examples> data = mapper.findAsPage(offset, rows);
		pages.setRows(data);
		int totalCount = mapper.getCount();
		pages.setTotal(totalCount);
		return pages;
	}

	@Override
	public boolean update(Examples examples) {
		return mapper.update(examples) > 0;
	}

	@Override
	public boolean delete(Integer id) {
		return mapper.delete(id) > 0;
	}

}
